#define DEBUG
#include <cstdio>

using namespace std;

const int maxn=2000, maxm=2000;

int n, m, x=1, y=1, board[maxn+1][maxm+1], warp[maxn+1][maxm+1][2], warpver=1;

void move(int k) {
  static int ver=1, book[maxn+1][maxm+1], time[maxn+1][maxm+1];
  int cnt = 0;
  ver++;
  for (; k>0; k--) {
    book[x][y] = ver;
    time[x][y] = cnt;
    if (warp[x][y][0]==warpver) {
      k = k%warp[x][y][1];
    }
    if (k>0) {
      int ny = y%m+1, ax=(x-2+n)%n+1, bx=x, cx=x%n+1;
      if (board[ax][ny]>board[bx][ny] && board[ax][ny]>board[cx][ny]) {
	x = ax, y = ny;
      } else if (board[bx][ny]>board[ax][ny] && board[bx][ny]>board[cx][ny]) {
	x = bx, y = ny;
      } else {
	x = cx, y = ny;
      }
      cnt++;
      if (book[x][y]==ver && warp[x][y][0]!=warpver) {
	warp[x][y][0] = warpver;
	warp[x][y][1] = cnt-time[x][y];
      }
    }
  }
}

int read() {
  char c;
  int ret=0;
  for (c=getchar(); c<'0' || c>'9'; c=getchar());
  for (; c>='0' && c<='9'; c=getchar()) {
    ret = ret*10+c-'0';
  }
  return ret;
}

int main() {
  freopen("jump.in", "r", stdin);
  freopen("jump.out", "w", stdout);

  n=read(), m=read();
  for (int i=1; i<=n; i++) {
    for (int j=1; j<=m; j++) {
      scanf("%d", &board[i][j]);
    }
  }

  int q;
  q=read();
  char type;
  for (int i=1; i<=q; i++) {
    for (type=getchar(); type!='m' && type!='c'; type=getchar());
    if (type=='m') {
      int k=read();
      move(k);
      printf("%d %d\n", x, y);
    } else {
      int a=read(), b=read(), k=read();
      warpver++;
      board[a][b] = k;
    }
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
